package com.vogue.network.core;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.vogue.network.data.NetConstants;
import com.vogue.network.util.NetLogUtil;
import com.vogue.network.util.NetworkUtil;

/**
 * 网络变化主播监听
 */
public class NetworkStateReceiver extends BroadcastReceiver {

    private static final String TAG = "NetworkStateReceiver";

    private NetDispatcher mNetDispatcher;

    public NetworkStateReceiver(NetDispatcher netDispatcher) {
        mNetDispatcher = netDispatcher;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null || intent.getAction() == null) {
            return;
        }
        if (NetConstants.NET_CHANGE_ACTION.equals(intent.getAction())) {
            NetLogUtil.d(TAG, "_onReceive(), 网络发生了变化...");
            mNetDispatcher.post(NetworkUtil.getNetType());
        }
    }

}
